﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CefSharp;
using CefSharp.WinForms;
using pinduoduo.Util;
using Sunny.UI;

namespace AutoPay
{
    public partial class Form1 : UIForm
    {
        private ChromiumWebBrowser AccountChromeBrowser;

        private RequestContext AccountContext;

        private string url;

        public bool IsLoadEnded { get; set; }

        public Form1(string url)
        {
            this.url = url;
            InitializeComponent();
            InitializeAccountChromium();
        }


        //初始化浏览器并启动
        public void InitializeAccountChromium()
        {

            AccountContext = new RequestContext(new RequestContextSettings()
            {
                CachePath = AppDomain.CurrentDomain.BaseDirectory + "caches\\global1\\",
                PersistSessionCookies = true,
                PersistUserPreferences = true
            });

            AccountChromeBrowser = new ChromiumWebBrowser(this.url, AccountContext);
            BrowserSettings browserSettings = new BrowserSettings();
            browserSettings.ApplicationCache = CefState.Enabled;
            AccountChromeBrowser.KeyboardHandler = new CEFKeyBoardHander();
            AccountChromeBrowser.BrowserSettings = browserSettings;

            this.Controls.Add(AccountChromeBrowser);

            AccountChromeBrowser.Dock = DockStyle.Fill;
            AccountChromeBrowser.FrameLoadEnd += (_, __) => IsLoadEnded = true;
        }

    }
}
